package com.haixiaoke.saas.enterprise.house.controller;

import com.haixiaoke.saas.common.annotation.RepeatSubmit;
import com.haixiaoke.saas.common.core.domain.AjaxResult;
import com.haixiaoke.saas.common.utils.poi.ExcelUtil;
import com.haixiaoke.saas.house.domain.Decoration;
import com.haixiaoke.saas.house.service.IDecorationService;
import com.haixiaoke.saas.system.BaseController;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.web.bind.annotation.*;

import javax.servlet.http.HttpServletResponse;
import java.util.List;

/**
 * 装修情况Controller
 *
 * @author xiaolong
 * @date 2023-10-25
 */
@RestController
@RequestMapping("/enterprise/house/decoration")
public class EnterpriseDecorationController extends BaseController {
    @Autowired
    private IDecorationService decorationService;

    /**
     * 查询装修情况列表
     */
    @PreAuthorize("@ss.hasPermi('business:decoration:list')")
    @GetMapping("/list")
    public AjaxResult list(Decoration decoration) {
        List<Decoration> list = decorationService.selectDecorationList(decoration);
        return AjaxResult.success(list);
    }

    /**
     * 导出装修情况列表
     */
    @PreAuthorize("@ss.hasPermi('business:decoration:export')")
    @PostMapping("/export")
    public void export(HttpServletResponse response, Decoration decoration) {
        List<Decoration> list = decorationService.selectDecorationList(decoration);
        ExcelUtil<Decoration> util = new ExcelUtil<Decoration>(Decoration.class);
        util.exportExcel(response, list, "装修情况数据");
    }

    /**
     * 获取装修情况详细信息
     */
    @PreAuthorize("@ss.hasPermi('business:decoration:query')")
    @GetMapping(value = "/{decorationId}")
    public AjaxResult getInfo(@PathVariable("decorationId") Long decorationId) {
        return success(decorationService.selectDecorationByDecorationId(decorationId));
    }

    /**
     * 新增装修情况
     */
    @PreAuthorize("@ss.hasPermi('business:decoration:add')")
    @PostMapping
    @RepeatSubmit
    public AjaxResult add(@RequestBody Decoration decoration) {
        return toAjax(decorationService.insertDecoration(decoration));
    }

    /**
     * 修改装修情况
     */
    @PreAuthorize("@ss.hasPermi('business:decoration:edit')")
    @PutMapping
    @RepeatSubmit
    public AjaxResult edit(@RequestBody Decoration decoration) {
        return toAjax(decorationService.updateDecoration(decoration));
    }

    /**
     * 删除装修情况
     */
    @PreAuthorize("@ss.hasPermi('business:decoration:remove')")
    @DeleteMapping("/{decorationIds}")
    @RepeatSubmit
    public AjaxResult remove(@PathVariable Long[] decorationIds) {
        return toAjax(decorationService.deleteDecorationByDecorationIds(decorationIds));
    }
}
